#include <sys/epoll.h>
#include <iostream>

const uint32_t EVENTIN = EPOLLIN;
const uint32_t EVENTOUT = EPOLLOUT;

class Epoll
{
public:
    Epoll() 
    { 
        create();
    }
    ~Epoll() { }
    void create()
    {
        _fd = epoll_create(128);
        if(_fd < 0)
        {
            std::cout << "epollcreat error" << std::endl;
        }
        std::cout << "epollcreat right, fd : " << _fd << std::endl;
    }
    int wait(struct epoll_event* events, int maxevents, int timeout = -1)
    {
        return epoll_wait(_fd, events, maxevents, timeout);
    }
    void ctl(int op, int fd, uint32_t EVENT)
    {
        int n = 0;
        if(op == EPOLL_CTL_DEL)
        {
            n = epoll_ctl(_fd, op, fd, nullptr);
            if(n < 0)
            {
                std::cout << "epollctl error" << std::endl;
            }
        }
        else
        {
            struct epoll_event event;
            event.events = EVENT;
            event.data.fd = fd;
            n = epoll_ctl(_fd, op, fd, &event);
            if(n < 0)
            {
                std::cout << "epollctlADD error" << _fd << fd << std::endl;
            }
        }
    }
private:
    int _fd;
};